package com.bolang.onlycode.demo.juc;

import java.io.IOException;
import java.util.concurrent.*;

public class ThreadPerTaskWebServer {
    final static ExecutorService threadPool = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        Runnable task = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        if(i==3){
                            Thread.sleep(1000);
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
                    int total = Thread.activeCount();
                    Thread[] threads = new Thread[total];
                    threadGroup.enumerate(threads);
                    for(Thread t : threads){
                        System.out.println(t.getName()+t.isAlive()+"---------"+t.getState());
                    }
                    System.out.println();
                }
                handleRequest("aa");
            }
        };
        Future<?> submit = threadPool.submit(task);
        System.out.println("main线程停止了");
        TimeUnit.SECONDS.sleep(1);
    }

    private static String handleRequest(String connection) {
        // 处理请求逻辑
        // System.out.println(connection);
        return  connection;
    }
}
